<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Fault extends Model
{
    use SoftDeletes;

    protected $table = 'faults';
    const CLOSED = 1;



    protected $fillable = [
        'state','fault_desc','update_grip_id','chest_id','grip_id','handle_way','type_id','user_id',
    ];

    public function chest()
    {
        return $this->belongsTo(Chest::class, 'chest_id');
    }

    public function grip()
    {
        return $this->belongsTo(Grip::class, 'grip_id');
    }

    public function isClosed()
    {
        return $this->state == self::CLOSED;
    }
    //获取用户信息
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }
    public function getHumanStatusAttribute()
    {
        $statusArr = [
            0 => '未维修',
            1 => '已维修',
            2 => '维修中'
        ];
        return array_get($statusArr, $this->state);
    }
}
